package com.yingside.system.mapper;

import com.yingside.system.model.Menu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yingside
 * @since 2020-12-30
 */
@Repository
public interface MenuMapper extends BaseMapper<Menu> {

    @Select("select distinct menu.menu_id," +
            "   menu.parent_id," +
            "   menu.menu_name," +
            "   menu.url," +
            "   menu.perms," +
            "   menu.order_num," +
            "   menu.icon " +
            "   from    user," +
            "           role," +
            "           user_role," +
            "           menu," +
            "           role_menu " +
            "        where user.user_id = user_role.user_id " +
            "          and role.role_id = user_role.role_id " +
            "          and role.role_id = role_menu.role_id " +
            "          and menu.menu_id = role_menu.menu_id " +
            "          and user.username = #{username}")
    @ResultMap(value = "com.yingside.system.mapper.MenuMapper.menuMap")
    List<Menu> selectMenuByUserName(@Param("username") String username);

    List<Menu> selectAllTree();
}
